from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')
from web_base.base_page_asset import BasePage

class LoginPage(BasePage):
    url=r'/bsams/front/login.do'
    #登录定位
    id_loc = (By.ID, 'taskId')
    username_loc = (By.ID, 'loginName')
    pwd_loc = (By.ID, 'password')
    identify_loc = (By.ID, 'vericode')
    login_btn_loc = (By.XPATH, '//*[@id="fmedit"]/div[2]/div[6]/input')
    logout_btn_loc = (By.XPATH,'/html/body/div[1]/div/div[2]/a[3]')
    def login(self,id=1,username='test11',pwd='1234567',identify='shtd'):
        self.open()
        self.input_ele(self.id_loc, id)
        sleep(1)
        self.input_ele(self.username_loc, username)
        sleep(1)
        self.input_ele(self.pwd_loc, pwd)
        sleep(1)
        self.input_ele(self.identify_loc, identify)
        sleep(1)
        self.ele_click(self.login_btn_loc)
        sleep(5)
    def logout(self):
        # self.login(id=1,username='test11',pwd='1234567',identify='shtd')
        self.ele_click(self.logout_btn_loc)
        sleep(2)

if __name__ == '__main__':
    id = 1
    username = 'test11'
    pwd = '1234567'
    identify = 'shtd'

    chrome_location = r'D:\chrom browser\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location
    dr = webdriver.Chrome(options=options)
    login_page=LoginPage(dr)
    login_page.login(id,username,pwd,identify)
    login_page.logout()
    dr.quit()